package com.java1412.order.controller;

import com.java1412.common.entity.Goods;
import com.java1412.order.service.GoodsService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 商品订单信息
 *
 * @author java1412
 * @since 2023-06-08 10:22:44
 */
@RestController
@RequestMapping("/api/v1/goods_order")
public class OrderController {
    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("/getGoods")
    public Goods save(Integer goodsId) {
        return restTemplate.getForObject("http://localhost:6001/api/v1/goods/findByGoodsId?goodsId=" + goodsId, Goods.class);
    }

    @Resource
    private GoodsService goodsService;

    @RequestMapping("/getGoodsByFeign")
    public Goods getGoodsByFeign(Integer goodsId) {
        Goods goods = goodsService.findByGoodsId(goodsId);
        return goods;
    }

    @RequestMapping("/findClusterName")
    public String findClusterName() {
        // 模拟十次请求100000
        for (int i = 0; i < 10; i++) {
            System.out.println(goodsService.findClusterName());
        }

        return "执行结束";
    }
}
